package com.yunhai.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.core.controller.BaseController;
import com.yunhai.common.core.page.TableDataInfo;
import com.yunhai.common.enums.ReportTypeEnum;
import com.yunhai.system.domain.Environmental;
import com.yunhai.system.domain.InvestorRelation;
import com.yunhai.system.service.IInvestorRelationService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description: InvestorRelationController
 * @Author: jxj
 * @Date: 2021/1/22 10:33
 */
@RestController
@RequestMapping("/api/relation/")
public class InvestorRelationController extends BaseController {

    @Autowired
    private IInvestorRelationService investorRelationService;

    /**
     * 公司报告
     * @param param
     * @return
     */
    @PostMapping("companyReport")
    private TableDataInfo companyReport(@RequestBody Map<String, Object> param) {
        Integer type = MapUtils.getInteger(param, "type");
        if (type == null) {
            type = ReportTypeEnum.COMPANY.getCode();
        }

        Long page = MapUtils.getLong(param, "page", 1L);
        Long limit = MapUtils.getLong(param, "limit", 10L);
        QueryWrapper<InvestorRelation> investorRelationQueryWrapper = new QueryWrapper<>();
        investorRelationQueryWrapper.orderByDesc("push_time","create_time");
        investorRelationQueryWrapper.eq("type", type);
        IPage<InvestorRelation> pageResult = investorRelationService.page(new Page<>(page, limit), investorRelationQueryWrapper);
        return new TableDataInfo(pageResult.getRecords(), (int) pageResult.getTotal());
    }

}
